package com.wt.controller;

import com.wt.common.ResultData;
import com.wt.entities.Account;
import com.wt.mapper.AccountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created with IDEA
 * Describe:
 * Author:tianji
 * Date:2018/11/1
 * Time:18:40
 */
@Controller
public class AccountController {

    @Autowired
    private AccountMapper accountMapper;

    @RequestMapping("/getAll")
    @ResponseBody
    public ResultData getAllAccount(){
        List<Account> allAccount = accountMapper.getAllAccount();
        return ResultData.build(0,"success",allAccount);
    }

    @RequestMapping("/getAccountById")
    @ResponseBody
    public ResultData getAccountById(String id){
        Account account = accountMapper.getAccountById(id);
        return ResultData.build(0,"success",account);
    }

    @RequestMapping("/delAccountById")
    @ResponseBody
    public ResultData deleteAccount(String id){
        int i = accountMapper.deleteAccount(id);
        return ResultData.build(0,"success",i);
    }

    @RequestMapping("/insertAccount")
    @ResponseBody
    public ResultData insertAccount(Account account){
        int i = accountMapper.insertAccount(account);
        return ResultData.build(0,"success",account);
    }
}
